﻿namespace NetFx.MSIL
{
  using System;
  using System.Text;
  using System.Threading;
  using System.Collections;

  using System.Reflection;
  using System.Reflection.Emit;

  public class VariableGenerator:AnyGenerator
  {
    #region Statics
    public static VariableGenerator of(string name, Type variableType, int index, bool isPinned, LocalBuilder builder)
    {
      return new VariableGenerator(name,variableType,index,isPinned,builder);
    }
    #endregion
    #region Fields
    protected LocalBuilder builder = null;
    protected string name = string.Empty;
    protected int index = 0;
    protected bool isPinned = false;
    protected Type variableType = null;
    #endregion
    #region Properties
    public override object AnyBuilder
    {
      get { return this.builder; }
    }
    public override DefType GeneratorType
    {
      get
      {
        return DefType.Variable;
      }
    }
    public virtual LocalBuilder Builder
    {
      get
      {
        return this.builder;
      }
    }
    public virtual string Name
    {
      get
      {
        return this.name;
      }
      set
      {
        this.name = value;
      }
    }
    public virtual Type VariableType
    {
      get
      {
        return this.variableType;
      }
      set
      {
        this.variableType = value;
      }
    }
    public virtual int Index
    {
      get
      {
        return this.index;
      }
      set
      {
        this.index = value;
      }
    }
    public virtual bool IsPinned
    {
      get
      {
        return this.isPinned;
      }
      set
      {
        this.isPinned = true;
      }
    }
    #endregion
    #region Constructors
    public VariableGenerator(string name,Type variableType,int index,bool isPinned,LocalBuilder builder)
    {
      if (builder == null) throw new ArgumentNullException("builder can not be null!");
      if (variableType == null) throw new ArgumentNullException("parameterType can not be null!");
      this.name = name;
      this.index = index;
      this.isPinned = isPinned;
      this.builder = builder;
      this.variableType = variableType;
    }
    #endregion
    #region Utils
    protected override void Dispose(bool disposing)
    {
      if (disposing)
      {
        this.name = null;
        this.variableType = null;
        this.builder = null;
      }
    }
    #endregion
  }
}
